<template>
  <section>
    <input class="file" name="file" type="file" accept="image/png,image/gif,image/jpeg" @change="update"/>
  </section>
</template>

<script>
  import axios from 'axios';
  export default {
    name: 'test-file-upload',
    data() {
      return {}
    },
    methods: {
      update(e) {
        let file = e.target.files[0];
        let param = new FormData(); //创建form对象
        param.append('files', file);//通过append向form对象添加数据
        console.log(param.get('files')); //FormData私有类对象，访问不到，可以通过get判断值是否传进去
        let config = {
          headers: { 'Content-Type': 'multipart/form-data' }
        };
        //添加请求头
        axios.post('http://img.fsthz.com/upload-web.php', param, config)
          .then(response => {
            console.log(response.data);
          })
      }
    }
  }
</script>

<style lang="scss"></style>
